package web.response;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ResponseDemo1", value = "/ResponseDemo1")
public class ResponseDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("resp1....");
        /*//重定向
        //设置响应状态码
        response.setStatus(302);
        //设置响应头
        response.setHeader("location","/tomcat-demo1/ResponseDemo2");*/

        //简化方式完成重定向
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/ResponseDemo2");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
